package com.benjaminwan.read.free.base.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.benjaminwan.read.free.utils.hideSoftInput

abstract class BaseDialogFragment<T : ViewBinding> : BaseMvRxDialogFragment() {

    abstract var binding: T

    private fun refreshWindow() {
        val window = dialog?.window ?: return
        window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val params = window.attributes
        params.width = ViewGroup.LayoutParams.WRAP_CONTENT
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT
        window.attributes = params
    }

    fun refreshDialog() {
        binding.root.post { refreshWindow() }
    }

    override fun onDestroyView() {
        hideSoftInput()
        super.onDestroyView()
    }
}